﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;
using DAL;
using System.Data;

public partial class Page_RealT : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            HiddenField1.Value = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            MembershipUser user = Membership.GetUser();
            int frameLevel=QuerySQL.GetUserFrameLevel((Guid)user.ProviderUserKey);
            if(frameLevel==-1)
            {
                if (user.UserName == "wangf0228")
                    HiddenField2.Value = "0";
                else
                 {
                    FormsAuthentication.SignOut();
                    //Response.Redirect("~/Page/Default.aspx");
                    Page.ClientScript.RegisterStartupScript(this.GetType(), "", " <script lanuage=javascript>alert('帐户存在异常，请联系管理员');window.location.href='Default.aspx'</script>");
                }
            }
            else
            {
                HiddenField2.Value = frameLevel.ToString();
            }
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        int frameLevel = int.Parse(HiddenField2.Value);
        DateTime time=DateTime.Parse(HiddenField1.Value);
        DataTable dt=new DataTable();
        switch (frameLevel)
        {
            case 0:
                dt=QuerySQL.RealT_Frame0(time);
                break;
            case 1:
                dt = QuerySQL.RealT_Frame1(time);
                break;
            case 2:
                dt = QuerySQL.RealT_Frame2(time);
                break;
            case 3:
                dt = QuerySQL.RealT_Frame3(time);
                break;
            case 4:
                dt = QuerySQL.RealT_Frame4(time);
                break;
        }
        GridView1.DataSource = dt;
        GridView1.DataBind();
    }
    protected void Timer1_Tick(object sender, EventArgs e)
    {
        Button1_Click(null, null);
    }
    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        switch (DropDownList1.SelectedIndex)
        {
            case 0:
                Timer1.Interval = 5000;
                break;
            case 1:
                Timer1.Interval = 10000;
                break;
            case 2:
                Timer1.Interval = 20000;
                break;
            case 3:
                Timer1.Interval = 30000;
                break;
            case 4:
                Timer1.Interval = 60000;
                break;
        }
    }
}